package com.szy.assembly;

import java.io.Serializable;
import java.util.HashMap;

public enum InstructionEnum implements Serializable {
    IMM,
    MOV,
    LD,
    ST,

    POP,
    PUSH,

    ADD,
    SUB,
    MUL,
    DIV,
    INC,
    DEC,

    AND,
    OR,
    NOT,
    XOR,

    LTH,
    MTH,
    EQ,

    J,
    JE,
    JNE,
    JZ,
    JNZ,
    DJZ,
    DJNZ,

    CALL,
    RET,

    NOP,


    ;
    public static HashMap<InstructionEnum,Integer> opcodeLength=new HashMap<InstructionEnum,Integer>(){
        {
            put(InstructionEnum.IMM,2);
            put(InstructionEnum.MOV,2);
            put(InstructionEnum.LD,2);
            put(InstructionEnum.ST,2);
            put(InstructionEnum.ADD,3);
            put(InstructionEnum.SUB,3);
            put(InstructionEnum.INC,1);
            put(InstructionEnum.DEC,1);
            put(InstructionEnum.MUL,3);
            put(InstructionEnum.DIV,4);
            put(InstructionEnum.AND,3);
            put(InstructionEnum.NOT,2);
            put(InstructionEnum.OR,3);
            put(InstructionEnum.XOR,3);
            put(InstructionEnum.LTH,3);
            put(InstructionEnum.MTH,3);
            put(InstructionEnum.EQ,3);
            put(InstructionEnum.J,1);
            put(InstructionEnum.JE,3);
            put(InstructionEnum.JNE,3);
            put(InstructionEnum.JZ,2);
            put(InstructionEnum.JNZ,2);
            put(InstructionEnum.DJZ,2);
            put(InstructionEnum.DJNZ,2);
            put(InstructionEnum.NOP,0);
            put(InstructionEnum.CALL,1);
            put(InstructionEnum.RET,0);
        }
    };
    public static HashMap<String,InstructionEnum> instructionRecognizer=new HashMap<String,InstructionEnum>(){
        {
            put("imm",  InstructionEnum.IMM);
            put("mov",  InstructionEnum.MOV);
            put("ld",  InstructionEnum.LD);
            put("st",  InstructionEnum.ST);
            put("add",  InstructionEnum.ADD);
            put("sub",  InstructionEnum.SUB);
            put("inc",  InstructionEnum.INC);
            put("dec",  InstructionEnum.DEC);
            put("mul",  InstructionEnum.MUL);
            put("div",  InstructionEnum.DIV);
            put("and",  InstructionEnum.AND);
            put("not",  InstructionEnum.NOT);
            put("or",   InstructionEnum.OR);
            put("xor",  InstructionEnum.XOR);
            put("lth",  InstructionEnum.LTH);
            put("mth",  InstructionEnum.MTH);
            put("eq",  InstructionEnum.EQ);
            put("j",    InstructionEnum.J);
            put("je",   InstructionEnum.JE);
            put("jne",  InstructionEnum.JNE);
            put("jz",   InstructionEnum.JZ);
            put("jnz",  InstructionEnum.JNZ);
            put("djz",  InstructionEnum.DJZ);
            put("djnz",  InstructionEnum.DJNZ);
            put("nop",  InstructionEnum.NOP);
            put("call",  InstructionEnum.CALL);
            put("ret",  InstructionEnum.RET);
        }
    };
}
